---
--类名: Entity.lua
--创建日期: 2018-1-12
--创建人: 陈小虎
--功能描述: 
--修改内容：
--修改日期:   
--修改人:     
--修改备注: 

local EntityExtend = import(".EntityExtend")
local Entity = class("Entity")

function Entity:ctor()
	self.id = nil
	self.leader = nil
	self.faceTo = nil
	self.status = nil
	self.posX = nil
	self.info = nil
	self.behavior = nil
	self.extend = nil
	self.baseInfoUpdate = false
end

function Entity:read(pbData)
	if not pbData then return end

	self.id = pbData.id  -- id's type is number
	self.leader = pbData.leader
	self.faceTo = pbData.faceTo
	self.status = pbData.status
	self.posX = pbData.posX
	self.behavior = pbData.behavior
	-- 扩展信息
	self.extend = EntityExtend.new(pbData.extend)
	local info = pbData.info
	if info then
		if not self.info then
			self.info = UserBaseInfo.new(info)
		else
			self.info:read(info)
		end
		self:setBaseInfoUpdate(true)
	end

	-- print("--------- Entity:read --------- ")
	-- if self.id == app.session.uid then
	-- 	print("--------- Entity:read --------- self ")
	-- end
	-- print(">>>>>> self.id = ",self.id)
	-- print(">>>>>> self.leader = ",self.leader)
	-- print(">>>>>> self.faceTo = ",self.faceTo)
	-- print(">>>>>> self.status = ",self.status)
	-- print(">>>>>> self.posX = ",self.posX)
	-- dump(self.info)
end

function Entity:getId()
	return self.id
end

function Entity:getMountId()
	if self:getInfo() then
		return self:getInfo().mountID
	end
	return nil
end

function Entity:getX()
	return self.posX
end

function Entity:getBehavior()
	return self.behavior
end

function Entity:setInfo(newInfo)
	self.info = newInfo
end

function Entity:getInfo()
	return self.info
end

function Entity:setBaseInfoUpdate(isUpdate)
	self.baseInfoUpdate = isUpdate
end

function Entity:isBaseInfoUpdate()
	return self.baseInfoUpdate
end

function Entity:isFaceToLeft()
	return self.faceTo == Enums.FaceTo.left
end

function Entity:isFaceToRight()
	return self.faceTo == Enums.FaceTo.right
end

function Entity:isIdle()
	return self.status == Enums.status.idle
end

function Entity:getLeaderId()
	return self.leader
end

function Entity:getHpPercent()
	if not self.extend then return 0 end
	return self.extend:getHpPercent()
end

function Entity:getFieldTag()
	if not self.extend then return 0 end
	return self.extend:getFieldTag()
end

return Entity